package com.gt.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gt.common.annotation.Log;
import com.gt.common.core.controller.BaseController;
import com.gt.common.core.domain.AjaxResult;
import com.gt.common.core.page.TableDataInfo;
import com.gt.common.enums.BusinessType;
import com.gt.admin.domain.ProjectInfo;
import com.gt.admin.domain.vo.ProjectInfoVO;
import com.gt.admin.service.IProjectInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目信息controller
 */
@Api(tags = "sc-项目信息管理")
@RestController
@RequestMapping("/config-project-information")
public class ProjectInfoController extends BaseController {
    @Autowired
    private IProjectInfoService projectInfoService;


    /**
     * 新增项目信息
     */
    @ApiOperation("新增项目信息")
    @Log(title = "项目信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult insert(@RequestBody ProjectInfoVO projectInfoVO){
        return toAjax(projectInfoService.add(projectInfoVO));
    }

    /**
     * 修改项目信息
     */
    @ApiOperation("修改项目信息")
    @Log(title = "项目信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult update(@RequestBody ProjectInfoVO projectInfoVO){
        return toAjax(projectInfoService.update(projectInfoVO));
    }

    /**
     * 查询项目信息
     */
    @ApiOperation("查询项目信息")
    @GetMapping
    public TableDataInfo list(ProjectInfo projectInfo){
        startPage();
        LambdaQueryWrapper<ProjectInfo> queryWrapper = new LambdaQueryWrapper<>(projectInfo);
        List<ProjectInfo> list = projectInfoService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 按id查询项目信息
     */
    @ApiOperation("按id查询项目信息")
    @GetMapping("/{id}")
    public AjaxResult list(@PathVariable("id") Long id){
        ProjectInfoVO projectInfoVO = projectInfoService.selectById(id);
        return AjaxResult.success(projectInfoVO);
    }

    /**
     * 删除项目信息
     */
    @ApiOperation("删除项目信息")
    @Log(title = "项目信息管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{proId}")
    public AjaxResult delete(@PathVariable("proId")Long proId){
        return toAjax(projectInfoService.delete(proId));
    }
}
